package kr.co.doriclassic.chapter14;

import java.awt.Component;
import java.awt.HeadlessException;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
class MyBoxFrame extends JFrame{

	public MyBoxFrame() throws HeadlessException {
		setTitle("Box Layout");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JPanel panel = new JPanel();
		
		panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
		
		mekeButton(panel, "Button1");
		mekeButton(panel, "Button2");
		mekeButton(panel, "Button3");
		mekeButton(panel, "B4");
		mekeButton(panel, "Long Button5");
		
		add(panel);
		pack();
		setVisible(true);
	}

	private void mekeButton(JPanel panel, String text) {
		JButton button = new JButton(text);
		button.setAlignmentX(Component.CENTER_ALIGNMENT);;
		panel.add(button);		
	}
	
}

public class BoxTest extends JFrame {
	public static void main(String[] args) {
		new MyBoxFrame();
	}
}
